package cxm.com.util;

import java.util.ArrayList;
import java.util.List;

import android.view.View;
import android.view.ViewGroup;

public class ViewHelper {
	public static List<View> findViewWithTagRecursively(ViewGroup root, CompareFunction comparer, Object tag){
	    List<View> allViews = new ArrayList<View>();

	    final int childCount = root.getChildCount();
	    for (int i = 0; i < childCount; i++){
	        final View childView = root.getChildAt(i);

	        if (childView instanceof ViewGroup){
	          allViews.addAll(findViewWithTagRecursively((ViewGroup)childView, comparer, tag));
	        }
	        else{
	            final Object tagView = childView.getTag();
	            if(tagView != null && comparer.compare(tagView, tag))
	                allViews.add(childView);
	        }
	    }

	    return allViews;
	}
}
